package com.visec.hdy.hadoop.storage;

import java.io.File;
import java.io.InputStream;

import com.visec.hdy.hadoop.standard.FSB;
import com.visec.hdy.hadoop.standard.Analysis.Item;

/**
 * 文件存储实现类
 * 
 * @author hdy
 *
 * @param <K>
 */
public class FileStorageImpl<K> extends DefaultStorageImpl<K, InputStream> {
	private boolean isAppend;

	public FileStorageImpl(FSB fsb, boolean isAppend) {
		super(fsb);
		this.isAppend = isAppend;
	}

	@Override
	public void store(Item<K, InputStream> item) {
		File newFile = context.newFile(item.getKey());
		if (isAppend && this.fsb.isExist(newFile)) {
			this.fsb.append(newFile, item.getObject());
		} else {
			this.fsb.create(newFile, item.getObject());
		}
	}

}
